package descentFly.away3D4.action
{
	import away3d.containers.ObjectContainer3D;
	
	import descentFly.df_FData;
	
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	public class df_actionRotate extends df_OPAction {
		public static const FIELD_ROLL		: String = 'roll';
		public static const DEFAULT_ROLL	: Vector3D = new Vector3D(90, 0, 0);
		
		public function df_actionRotate(a_options:Object, a_model:ObjectContainer3D) {
			super(a_options, a_model);
			checkOption(FIELD_ROLL, DEFAULT_ROLL);
			options[FIELD_ROLL] = df_FData.parseVector(options[FIELD_ROLL]);
		}
		
		override protected function update(percent: Number): void {
			var roll: Vector3D = options[FIELD_ROLL].clone();
			roll.scaleBy(percent);
			objects.forEach(function (object: ObjectContainer3D, i: int, arr: Array): void {
				object.transform = updateMatrix(originMatrix[i].clone(), roll);
			});
		}
		
		protected function updateMatrix(mat: Matrix3D, curRoll: Vector3D): Matrix3D {
			mat.prependRotation(curRoll.x, Vector3D.X_AXIS);
			mat.prependRotation(curRoll.y, Vector3D.Y_AXIS);
			mat.prependRotation(curRoll.z, Vector3D.Z_AXIS);
			return mat;
		}
	}
}